﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using NS.BLL.Systems;
using NS.Utilities;
using NS.Model.Systems;

public partial class Systems_RoleManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GridBind();
        }
    }
    private void GridBind()
    {
        GridView1.SQLString = RoleService.GetAllRole_SQL(null);
        GridView1.PKey = "ID";
        GridView1.OrderName = "Weights DESC,ID DESC";
        GridView1.BindData();
        GridView1.AddControl();
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string roleName = txtRoleName.Text.Trim();
        if (!RoleService.RoleNameExists(roleName))
        {
            Role Model = new Role();
            Model.RoleName = txtRoleName.Text.Trim();
            Model.Weights = Convert.ToInt32(txtWeights.Text.Trim());
            Model.Memo = txtMemo.Text.Trim();
            if (RoleService.AddRole(Model) > 0)
            {
                GridBind();
                MessageBox.ShowSaveSuccess(this);
            }
        }
        else
        {
            MessageBox.ShowInfo(this, "岗位已存在！");
        }
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        RoleService.DeleteRoleById(Convert.ToInt32(((Button)sender).CommandArgument));
        GridBind();
    }
}
